package com.ymatou.iapi.notify.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.notify.parameter.SendNotifyBean;
import com.ymatou.iapi.notify.service.SendNotifyCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.NotifyCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.AgentUsers;

/**
*发送通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SendNotify{
	private static SendNotifyBean sendnotifyBean;
	private static SendNotifyCall sendnotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发送通知");
	}

	@Before
	public void caseUp() {
		sendnotifyBean=new SendNotifyBean();
		sendnotifyCall=new SendNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sendnotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendNotify_01() {
		Logger.start(true,"发送通知");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			//sendUserId从disconf配置文件中拿
			int sendUserId = 30156393;
			SendNotifyBean sendnotifyBean = NotifyCallService.initSendNotify(sendUserId,userId);
			sendnotifyCall.setData(sendnotifyBean);
			sendnotifyCall.callService();
			
			Logger.verifyEquals("Success",sendnotifyCall.getString("Status"),"验证Status");
			Map map = new ImDefaultWapper().selectImNotifyByToUserId(userId).get(0);
			Logger.verifyEquals(userId,Integer.parseInt(map.get("MsgToId").toString()),"验证接收方用户id");
			Logger.verifyEquals(sendUserId,Integer.parseInt(map.get("MsgFromId").toString()),"验证发送方id");
			Logger.verifyEquals(sendnotifyBean.getPushTitle(),map.get("PushTitle").toString(),"验证推送标题");
			Logger.verifyEquals(sendnotifyBean.getMessage(),map.get("Message").toString(),"验证推送内容");
			Logger.verifyEquals(sendnotifyBean.getEndTime()+".0",map.get("EndTime").toString(),"验证消息结束时间");
			Logger.verifyEquals(true,Integer.parseInt(map.get("IsRead").toString())==0?true:false,"验证是否已读");
			
		} catch (Exception e) {
			
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendNotify_02() {
		Logger.start(true,"发送方用户不存在");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int sendUserId = 26778436;
			SendNotifyBean sendnotifyBean = NotifyCallService.initSendNotify(sendUserId,userId);
			sendnotifyCall.setData(sendnotifyBean);
			sendnotifyCall.callService();
			Logger.verifyEquals("BussinessError",sendnotifyCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendNotify_03() {
		Logger.start(true,"接收方用户不存在");
		try {
//			Integer userId = AgentUsers.rootUserId;
//			int sendUserId = 19000002;
			Integer userId = 19000002;
			int sendUserId = AgentUsers.rootUserId;
			SendNotifyBean sendnotifyBean = NotifyCallService.initSendNotify(sendUserId,userId);
			sendnotifyCall.setData(sendnotifyBean);
			sendnotifyCall.callService();
			Logger.verifyEquals("BussinessError",sendnotifyCall.getString("Status"),"验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendNotify_04() {
		Logger.start(true,"微信代购神器，发送通知");
		try {
			Integer userId = AgentUsers.rootUserId;
			int sendUserId = 19000002;
			SendNotifyBean sendnotifyBean = NotifyCallService.initSendNotify(sendUserId,userId);
			sendnotifyCall.setData(sendnotifyBean);
			sendnotifyCall.callService();
			Logger.verifyEquals("Success",sendnotifyCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}